import java.util.Arrays;

public class MyArrayList {
    public int[] elem;
    public int size;

    public MyArrayList() {
        this.elem = new int[10];
    }

    public void display() {
        for (int i = 0; i < size; i++) {
            System.out.print(elem[i] + " ");
        }
        System.out.println();
    }

    public int size() {
        return this.size;
    }

    public boolean isfull() {
        return this.size == this.elem.length;
    }

    public void add(int pos, int data) {
        if (pos < 0 || pos > this.size) {
            System.out.println("pos位置不合法");
            return;
        }
        if (isfull()) {
            this.elem = Arrays.copyOf(this.elem, this.elem.length * 2);
        }
        for (int i = this.size - 1; i >= pos; i--) {
            elem[i + 1] = elem[i];
        }
        elem[pos] = data;
        this.size++;
    }

    public int toFind(int val) {
        for (int i = 0; i < this.size; i++) {
            if (val == elem[i]) {
                return i;
            }
        }
        return -1;
    }

    public boolean contains(int val) {
        int ret = toFind(val);
        if (ret == -1) {
            return false;
        } else {
            return true;
        }
    }

    public int search(int val) {
        int ret = toFind(val);
        return ret;
    }

    public int getpos(int pos) {
        for (int i = 0; i < this.size; i++) {
            if (i == pos) {
                return elem[i];
            }
        }
        return -1;
    }

    public void setpos(int pos, int val) {
        for (int i = 0; i < this.size; i++) {
            if (i == pos) {
                elem[i] = val;
            }
        }
    }

    public void remove(int toRemove) {
        int ret=toFind(toRemove);
        if(ret==-1) {
            System.out.println("要删除的元素不存在");
            return;
        }
        for (int i = ret; i < this.size-1; i++) {
            elem[i]=elem[i+1];
        }
        size--;
    }
    public void clear() {

    }

}